package com.wang.project.controller;


import com.wang.project.annotation.AuthCheck;
import com.wang.project.common.BaseResponse;
import com.wang.project.common.ResultUtils;
import com.wang.project.constant.UserConstant;
import com.wang.project.model.dto.approval.ApprovalQueryRequest;
import com.wang.project.model.dto.approval.ApprovalReSubmitRequest;
import com.wang.project.model.dto.approval.ApprovalSubmitRequest;
import com.wang.project.model.vo.ApprovalVO;
import com.wang.project.service.ApprovalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/approval")
public class ApprovalController {
    /**
     * 1. 获取审核列表
     * 2. 更新审核状态 或者审核信息
     * 审核完成后就直接发布接口
     * 审核完成之后获得积分
     */
    @Resource
    private ApprovalService approvalService;

    /**
     * 获取审核列表
     *
     * @param approvalQueryRequest
     * @param request
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<ApprovalVO>> getApprovalList(ApprovalQueryRequest approvalQueryRequest, HttpServletRequest request) {
        List<ApprovalVO> approvalVOS = approvalService.getApprovalList(approvalQueryRequest, request);
        return ResultUtils.success(approvalVOS);
    }

    // todo 分页懒得写了 直接拿list数据

    /**
     * 管理员审核
     *
     * @param approvalSubmitRequest
     * @param request
     * @return
     */
    @PostMapping("/submit")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> approvalSubmit(@RequestBody ApprovalSubmitRequest approvalSubmitRequest, HttpServletRequest request) {
        Boolean result = approvalService.approvalSubmit(approvalSubmitRequest, request);
        return ResultUtils.success(result);
    }


    /**
     * 用户重新提交审核
     *
     * @param approvalReSubmitRequest
     * @param request
     * @return
     */
    @PostMapping("/reSubmit")
    public BaseResponse<Boolean> approvalReSubmit(@RequestBody ApprovalReSubmitRequest approvalReSubmitRequest, HttpServletRequest request) {
        Boolean result = approvalService.approvalReSubmit(approvalReSubmitRequest, request);
        return ResultUtils.success(result);
    }

}
